package jfds.interfaces;

import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

import com.sun.awt.AWTUtilities;

public final class PantallaCarga extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel PanelC;
	private PantallaCarga splash = this;
	JProgressBar Progreso = new JProgressBar();
	JLabel lblCarga = new JLabel("");
	
	/**
	 * Create the frame.
	 */
	public PantallaCarga() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(PantallaCarga.class.getResource("/jfds/imges/iconos/f-spot.png")));
		setName("BienvenidaFrame");
		setUndecorated(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 663, 312);
		PanelC = new JPanel();
		PanelC.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(PanelC);
		PanelC.setLayout(null);
		lblCarga.setIcon(null);
		
		lblCarga.setHorizontalAlignment(SwingConstants.CENTER);
		lblCarga.setFont(new Font("Arial Black", Font.PLAIN, 15));
		lblCarga.setBounds(244, 267, 318, 33);
		PanelC.add(lblCarga);
		
		Progreso.setForeground(new Color(255, 228, 196));
		Progreso.setBounds(244, 253, 318, 16);
		PanelC.add(Progreso);
		
		JLabel lblJ = new JLabel("");
		lblJ.setIcon(new ImageIcon(PantallaCarga.class.getResource("/jfds/imges/j (1).png")));
		lblJ.setBounds(10, 0, 318, 308);
		PanelC.add(lblJ);
		
		JLabel lblFD = new JLabel("");
		lblFD.setHorizontalAlignment(SwingConstants.LEFT);
		lblFD.setIcon(new ImageIcon(PantallaCarga.class.getResource("/jfds/imges/fd.png")));
		lblFD.setBounds(58, 0, 597, 268);
		PanelC.add(lblFD);
		Iniciar();
	}

	public JProgressBar getProgreso() {
		return Progreso;
	}

	public void setProgreso(JProgressBar progreso) {
		Progreso = progreso;
	}

	public JLabel getLblCarga() {
		return lblCarga;
	}

	public void setLblCarga(JLabel lblCarga) {
		this.lblCarga = lblCarga;
	}

	public void Iniciar(){
		AWTUtilities.setWindowOpacity(splash, new Float(1.0));
		setLocationRelativeTo(null);
	    CargarHilo();
	}
    public void CargarHilo(){
    	Thread Hilo =  new Thread(new Runnable() {
			
			@Override
			public void run() {
				try{
					Principal Inicio = new Principal(splash);
					Inicio.setLocationRelativeTo(null);
					Inicio.setVisible(true);
				}catch(Exception e){
					JOptionPane.showMessageDialog(PanelC, "Error al Iniciar la Aplicacion", "Error de Inicio", ABORT);
					e.printStackTrace();	
				}
				dispose();
			}
		});
    	Hilo.start();
    }
}
